package com.mystyle.le.weekproject.asynctaks;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

import com.mystyle.le.weekproject.beans.Seniority;
import com.mystyle.le.weekproject.intentfactbackcall.MyCallBack;
import com.mystyle.le.weekproject.utils.DownData;
import com.mystyle.le.weekproject.utils.ParseJson;

import java.util.List;

/**
 * Created by le on 2016/10/9.
 */
public class SeniorityFragmentAsynctaks extends AsyncTask<String,Void,String> {

    private MyCallBack.HeadListBack seniorityBack;
    private Context context;
//    private ProgressDialog dialog;

    public SeniorityFragmentAsynctaks(MyCallBack.HeadListBack seniorityBack, Context context) {
        this.seniorityBack = seniorityBack;
        this.context = context;
    }

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
//        dialog = new ProgressDialog(context);
//        dialog.setTitle("正在下载");
//        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//        dialog.setMessage("请稍等...");
//        dialog.setCancelable(true);
//        dialog.show();
    }
    @Override
    protected String doInBackground(String... params) {
        boolean netWorkConn = DownData.isNetWorkConn(context);
        if (netWorkConn){
            String param = params[0];
            byte[] bytes = DownData.downData(param);
            if (bytes!=null&&bytes.length>0){
                String path = new String(bytes,0,bytes.length);
                return path;
            }
        }
       return null;
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
//        dialog.dismiss();
        if (s!=null){
            seniorityBack.sendBack(s);
        }
    }
}
